// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import Vue from 'vue'
import App from './App'
// import VueRouter from 'vue-router'
import router from './router'
import store from './store/'
// import Vant from 'vant'
import 'vant/lib/index.css'
import './assets/css/base.css'
import header from '@/components/common/v-header.vue'
import { Lazyload } from 'vant';//懒加载

Vue.config.productionTip = false

// Vue.use(VueRouter)
// Vue.use(Vant)

// options 为可选参数，无则不传 注册懒加载
Vue.use(Lazyload,  {
    error: './static/error.png'
});

//全局注册头部组件
Vue.component('v-header',header)

// const router = new VueRouter({
// 	routes
// })

//路由失败时的处理
let errorNums = 0;
router.onError((error) => {
    const pattern = /Loading chunk (\d)+ failed/g;
    const isChunkLoadFailed = error.message.match(pattern);
    const targetPath = router.history.pending.fullPath;
    if (isChunkLoadFailed && errorNums < 3) {
        errorNums++;
        router.replace(targetPath);
    }else{
        errorNums = 0;
        vant.Dialog.alert({
            message: '系统版本有更新，点击确认加载最新，或按【CTRL + F5】！'
        }).then(() => {
            store.dispatch('logout');
            window.location.reload(true);
        });
    }
})

new Vue({
	el: '#app',
    router,
	store,
	components: { App },
    template: '<App/>'
})

//设置当前登录相关信息
store.dispatch('login');